import uuid
from typing import Any

import pytest

from recruit.domain.models.resume_contact import (
    BaseResumeContact,
    ResumeContactCreate,
    ResumeContactResult,
    ResumeContactUpdate,
)
from .utils import check_attr_model, check_json_schema


@pytest.mark.parametrize(
    'data, keys', [(
            {
                'email': 'test@test.ru',
                'phone': '+79999999999',
                'telegram': '@telegram'
            },
            ('email', 'phone', 'telegram')
    )]
)
def test_resume_contact_base(
        data: dict[str, str],
        keys: tuple[str, ...]
) -> None:
    check_attr_model(BaseResumeContact, data)
    check_json_schema(BaseResumeContact, keys)
    for key, value in data.items():
        check_attr_model(
            BaseResumeContact,
            {key: value},
            tuple((k for k in data if k != key))
        )
    check_json_schema(BaseResumeContact, keys)


@pytest.mark.parametrize(
    'data', [
        {'telegram': 'telegram'},
        {'phone': 'phone'},
        {'email': 'email'},
        {'email': 'email@'},
        {'email': 'email@ml'},
        {'email': 'email@.com'},
    ]
)
def test_validate_in_resume_contact_base(data: dict[str, str]) -> None:
    with pytest.raises(ValueError):
        BaseResumeContact(**data)


@pytest.mark.parametrize(
    'data, keys', [(
            {
                'email': 'test@test.ru',
                'phone': '+79999999999',
                'telegram': '@telegram'
            },
            ('email', 'phone', 'telegram')
    )]
)
def test_resume_contact_create(
        data: dict[str, str],
        keys: tuple[str, ...]
) -> None:
    check_attr_model(ResumeContactCreate, data)
    check_json_schema(ResumeContactCreate, keys)
    for key, value in data.items():
        check_attr_model(
            ResumeContactCreate,
            {key: value},
            tuple((k for k in data if k != key))
        )
    check_json_schema(ResumeContactCreate, keys)


@pytest.mark.parametrize(
    'data', [
        {},
        {'telegram': 'telegram'},
        {'phone': 'phone'},
        {'email': 'email'},
        {'email': 'email@'},
        {'email': 'email@ml'},
        {'email': 'email@.com'},
    ]
)
def test_validate_in_resume_contact_create(data: dict[str, str]) -> None:
    with pytest.raises(ValueError):
        ResumeContactCreate(**data)


@pytest.mark.parametrize(
    'data, keys', [(
            {
                'id': uuid.uuid4(),
                'email': 'test@test.ru',
                'phone': '+79999999999',
                'telegram': '@telegram'
            },
            ('id', 'email', 'phone', 'telegram')
    )]
)
def test_resume_contact_result(
        data: dict[str, Any],
        keys: tuple[str, ...]
) -> None:
    check_attr_model(ResumeContactResult, data)
    check_json_schema(ResumeContactResult, keys)
    for key, value in data.items():
        if key == 'id':
            continue
        check_attr_model(
            ResumeContactResult,
            {
                'id': data['id'],
                key: value
            },
            tuple((k for k in data if k != key and k != 'id'))
        )
    check_json_schema(ResumeContactResult, keys)


@pytest.mark.parametrize(
    'data, keys', [(
            {
                'email': 'test@test.ru',
                'phone': '+79999999999',
                'telegram': '@telegram'
            },
            ('email', 'phone', 'telegram')
    )]
)
def test_resume_contact_update(
        data: dict[str, str],
        keys: tuple[str, ...]
) -> None:
    check_attr_model(ResumeContactUpdate, data)
    check_json_schema(ResumeContactUpdate, keys)
    check_attr_model(ResumeContactUpdate, {}, tuple(data))
    check_json_schema(ResumeContactUpdate, keys)
